/*
 * @lc app=leetcode.cn id=1422 lang=csharp
 *
 * [1422] 分割字符串的最大得分
 */

// @lc code=start
public class Solution
{
    public int MaxScore(string s)
    {
        int score = 0;
        int n = s.Length;
        if (s[0] == '0')
        {
            score++;
        }
        for (int i = 1; i < n; i++)
        {
            if (s[i] == '1')
            {
                score++;
            }
        }
        int ans = score;
        for (int i = 1; i < n - 1; i++)
        {
            if (s[i] == '0')
            {
                score++;
            }
            else
            {
                score--;
            }
            ans = Math.Max(ans, score);
        }
        return ans;
    }
}
// @lc code=end

